import { request } from './client'
import type { CalendarEvent, CreateEventRequest, UpdateEventRequest, UserActivity, ActivityStats, HeatmapData } from '@/types/calendar'

// 日历事件相关API
export const getCalendarEvents = (params: {
  year: number
  month: number
}) => {
  return request.get<CalendarEvent[]>('/calendar/events', params)
}

export const getEventsByDate = (date: string) => {
  return request.get<CalendarEvent[]>(`/calendar/events/${date}`)
}

export const createEvent = (data: CreateEventRequest) => {
  return request.post<CalendarEvent>('/calendar/events', data)
}

export const updateEvent = (id: number, data: UpdateEventRequest) => {
  return request.put<CalendarEvent>(`/calendar/events/${id}`, data)
}

export const deleteEvent = (id: number) => {
  return request.delete(`/calendar/events/${id}`)
}

export const getUpcomingEvents = (days: number = 7) => {
  return request.get<CalendarEvent[]>('/calendar/upcoming', { days })
}

// 用户活动相关API
export const getActivityHeatmap = (year?: number) => {
  return request.get<{
    activities: HeatmapData[]
    stats: ActivityStats
  }>('/activities/heatmap', year ? { year } : undefined)
}

export const getRecentActivities = (limit: number = 10) => {
  return request.get<UserActivity[]>('/activities/recent', { limit })
}

export const getActivityStats = (params?: {
  startDate?: string
  endDate?: string
}) => {
  return request.get<ActivityStats>('/activities/stats', params)
}

export const recordActivity = (data?: {
  date?: string
  count?: number
}) => {
  return request.post<UserActivity>('/activities', data)
}